<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="file" id="fileInput">
    <img src="" id="img" alt="">
</body>
</html>
<script>
    // // blob格式
    document.getElementById('fileInput').addEventListener('change', function(event) {
        let file = event.target.files[0];
        let fileReader = new FileReader();
        fileReader.readAsArrayBuffer(file);
        fileReader.onload = function () {
            let values = new Uint8Array(this.result);
            let img = document.getElementById("img");
            let file = new Blob([values], { type: "image/png" });
            console.log(URL.createObjectURL(file))
            img.src = URL.createObjectURL(file);
        };
    });

    // base64格式
    // document.getElementById('fileInput').addEventListener('change', function(event) {
    //     let file = event.target.files[0];
    //     let fileReader = new FileReader();
    //     fileReader.readAsDataURL(file);
    //     fileReader.onload = function () {
    //         let img = document.getElementById("img");
    //         img.src = this.result;
    //     };
    // })
</script>